import requests
import json
from lxml import etree
if __name__=='__main__':
    print('hello')
    url='https://www.bilibili.com/video/BV1ha4y1H7sx/?p=26'
    headers={
        'User-Agent':'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36'
    }
    response=requests.get(url=url,headers=headers)
    print('请求状态：',response.status_code)
    if response.status_code==200:
        print('结果:',response.text.__len__())
        tree=etree.HTML(response.text)
        #dd=tree.xpath('//head/script[3]/text()')
        title=tree.xpath('//div[@class=""]')
        print('title=',title)
        videoPlayInfo = str(tree.xpath('//head/script[3]/text()')[0].encode('utf-8').decode('utf-8'))[20:]
        #print(videoPlayInfo)
        videoJson = json.loads(videoPlayInfo)
        videoURL = videoJson['data']['dash']['video'][0]['baseUrl']
        audioURl = videoJson['data']['dash']['audio'][0]['baseUrl']
        #print("videoURL:",videoURL)
        #print("audioURl:",audioURl)